package com.chapter1;

import java.math.BigDecimal;
import java.util.Objects;

/**
 * 值比较工具类方法
 */
public class CompareToTest {
    public static void main(String[] args) {
//         String i = "0";
//         System.out.println(i.compareTo("2")); // -2
//         System.out.println(i.compareTo("0")); // 0
//         System.out.println(i.compareTo("-2")); // 3

        System.out.println(Objects.equals("2", "2")); // true
        System.out.println(Objects.equals("1", 1)); // false

        Integer i = 0;
        System.out.println(i.compareTo(2)); // -1
        System.out.println(i.compareTo(0)); // 0
        System.out.println(i.compareTo(-2)); // 1

        BigDecimal a = new BigDecimal("1.0");
        BigDecimal b = new BigDecimal("0.8");
        BigDecimal c = new BigDecimal("0.6");
        BigDecimal x = a.subtract(b); // 1.0 - 0.8 = 0.2
        BigDecimal y = b.subtract(c); // 0.8 - 0.6 = 0.2
        System.out.println("x="+x);
        System.out.println("y="+y);
        if (x.compareTo(y) == 0) {
            System.out.println("true");
        }
    }
}
